// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { show } = require("../game/alert");
const { shopData } = require("./gameData");

cc.Class({
    extends: cc.Component,

    properties: {
        foodName:cc.Label,
        price:cc.Label,
        stock:cc.Label,
        sales:cc.Label,
        transport:cc.Label,
        buyNum:Number,
        buyInput:cc.EditBox,
        commonBuy:cc.Button,
        agentBuy:cc.Button
    },
    handler() {
        let count = this.buyInput.string;
        if(typeof parseInt(count) == number){
            let money = count * count;
            if(shop.money < money){
                show('未来金融','您的账户余额不足');
                return;
            }
            return money;
        }
    },
    onEditor() {

    },
    buy(target, i) {
        //计算钱
        
       //正常购买
       shop.menuList.find(val => {
           if(val.id == target.target.parent.id){
               val.transport.push(Object.assign(val,{ count: this.buyNum}));
           }
       })
    },
    inputEvent(target, i) {

    },
    fastBuy(target, i) {
        
        shop.menuList.find(val => {
            if(val.id == target.target.parent.id){
                val.transport.push(Object.assign(val,{ count: this.buyNum}));
            }
        })
    },
    start () {

    },
    setMenuState (target,id) {

    }
    // update (dt) {},
});
